layui.use(['table', 'jquery','element','layer','form'], function () {
    var table = layui.table;
    var $ = layui.jquery;
    var element = layui.element;
    var layer = layui.layer;
    var form = layui.form;

    table.render({
        elem: '#table',
        height: 600,
        toolbar :'#toolbar',
        defaultToolbar : []
        , url: ctx + '/eng/user/clientList' //数据接口
        , page: true
        , cols: [[
            {field: 'name', title: '用户姓名', align: 'center',width:'18%'}
            , {field: 'phone', title: '客户电话', align: 'center',width:'15%'}
            , {field: 'registeTime', title: '注册时间', align: 'center',width:'15%'}
            , {field: 'shopName', title: '店铺名称', align: 'center',width:'15%'}
            , {field: 'managerName', title: '店主', align: 'center',width:'15%'}
            , {field: 'shopAddress', title: '店铺地址', align: 'center',width:'10%'}
            , {field: 'remain', title: '余额', align: 'center',width:'10%',templet : function(d){
                    return "<a href='#' style='color: #1E9FFF' class='remain_a' info='"+d.openId+"'>"+d.remain+"</a>";
                }}
            , {field: 'score', title: '积分', align: 'center',width:'10%',templet : function(d){
                    return "<a href='#' style='color: #1E9FFF' class='score_s' info='"+d.openId+"'>"+d.score+"</a>";
                }}
        ]]
    });

    // 客户数据导出
    // tool
    table.on('toolbar(table)', function(obj){
        var data = obj.data;
        var layEvent = obj.event;

        if(layEvent === 'export'){
            exportData(data);
        }
    });

    // 客户数据导出
    function exportData(){
        window.open(ctx+"/eng/user/export");
    }

    // 重置按钮
    $('#reset').click(function(){
        $('#queryReset').click();
    })

    // 条件查询
    $('#submit').click(function(){
        // 重新渲染数据
        table.reload('table', {
            url: ctx + '/eng/user/clientList'
            ,where: $('#queryForm').formToObject()
        });
        return false;
    });


    // 绑定余额的查询
    $('#main').on('click','.remain_a',function (e) {
        var openId = $(e.target).attr('info');
        window.open(ctx+'/eng/user/userRemain?openId='+openId);
    });

    // 绑定余额的查询
    $('#main').on('click','.score_s',function (e) {
        var openId = $(e.target).attr('info');
        window.open(ctx+'/eng/user/userScore?openId='+openId);
    });


});